package cn.iocoder.yudao.module.ordering.dal.mysql.record;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ordering.controller.admin.record.vo.RecordPageReqVO;
import cn.iocoder.yudao.module.ordering.dal.dataobject.record.RecordDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 餐品-订餐记录 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface RecordMapper extends BaseMapperX<RecordDO> {

    default PageResult<RecordDO> selectPage(RecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RecordDO>()
                .eqIfPresent(RecordDO::getFoodId, reqVO.getFoodId())
                .likeIfPresent(RecordDO::getName, reqVO.getName())
                .eqIfPresent(RecordDO::getType, reqVO.getType())
                .eqIfPresent(RecordDO::getPrice, reqVO.getPrice())
                .eqIfPresent(RecordDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(RecordDO::getOrderDate, reqVO.getOrderDate())
                .eqIfPresent(RecordDO::getUserId, reqVO.getUserId())
                .likeIfPresent(RecordDO::getUserName, reqVO.getUserName())
                .eqIfPresent(RecordDO::getDeptId, reqVO.getDeptId())
                .likeIfPresent(RecordDO::getDeptName, reqVO.getDeptName())
                .betweenIfPresent(RecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RecordDO::getOrderDate));
    }

    /**
     * 查询订餐记录
     *
     * @param
     * @return
     * @date 2024/7/26 17:59
     * @author lililiang
     */
    default List<RecordDO> selectListCommon(RecordDO recordParams){
        return selectList(new LambdaQueryWrapperX<RecordDO>()
                .eqIfPresent(RecordDO::getUserId, recordParams.getUserId())
                .inIfPresent(RecordDO::getStatus, recordParams.getStatusList())
                .betweenIfPresent(RecordDO::getOrderDate, recordParams.getOrderDates())
                .orderByDescIfPresent(RecordDO::getOrderDate, recordParams.getOrderDateOrderByDesc())
                .orderByAscIfPresent(RecordDO::getType, recordParams.getTypeOrderByAsc())
        );
    }
}
